package com.cloudcentral.controller;

import com.cloudcentral.entity.query.DetectResultQuery;
import com.cloudcentral.entity.vo.PageVO;
import com.cloudcentral.exception.FailureException;
import com.cloudcentral.service.DetectResultService;
import com.cloudcentral.util.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 探测结果记录表 前端控制器
 * </p>
 *
 * @author Administrator
 * @since 2023-11-23
 */
@Slf4j
@RestController
@RequestMapping("/detect-result")
@Tag(name = "探测结果")
public class DetectResultController extends BaseController {
  private final DetectResultService detectResultService;

  @Autowired
  public DetectResultController(DetectResultService detectResultService) {
    this.detectResultService = detectResultService;
  }

  @GetMapping("/listByIds")
  @Operation(summary = "根据ids查询结果")
  public Result<List<Map<String, Object>>> listByIds(String ids) throws FailureException {
    if (StringUtils.isBlank(ids)) throw new FailureException("缺少ids");
    else return Result.ok(detectResultService.listByIdsCustom(ids));
  }

  @GetMapping("/listPage")
  @Operation(summary = "分页查询")
  public Result<PageVO<Map<String, Object>>> listPage(DetectResultQuery query) throws FailureException {
    if (StringUtils.isBlank(query.getType()) && query.getDetectId() == null) throw new FailureException("缺少任务类型或任务ID");
    else return Result.ok(detectResultService.listPage(query));
  }
}
